package com.ts.enterprise.common.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;
import java.util.Map;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
public class BaseResponse<T> extends Page {
    public static final int SUCCESS_CODE = 0;
    /**
     * 状态码
     */
    @JsonProperty("errcode")
    protected Integer errCode;

    /**
     * 状态信息
     */
    @JsonProperty("errmsg")
    protected String errMsg;

    @ApiModelProperty("主键")
    private Long id;

    private T aData;

    protected List<T> data;

    @ApiModelProperty("其他信息")
    private Map<String, Object> infos;
    @ApiModelProperty("用户id")
    @JsonProperty("UserId")
    private String userId;
    @JsonProperty("DeviceId")
    private String deviceId;
    @JsonProperty("openid")
    private String openId;

    public BaseResponse() {
    }

    public BaseResponse(T aData) {
        this.aData = aData;
    }

    public BaseResponse(Integer errCode, String errMsg) {
        this.errCode = errCode;
        this.errMsg = errMsg;
    }

    public BaseResponse(Integer errCode, String errMsg, T aData) {
        this.errCode = errCode;
        this.errMsg = errMsg;
        this.aData = aData;
    }

    public BaseResponse(Integer errCode, String errMsg, Long id) {
        this.errCode = errCode;
        this.errMsg = errMsg;
        this.id = id;
    }

    public BaseResponse(Integer errCode, String errMsg, List<T> data) {
        this.errCode = errCode;
        this.errMsg = errMsg;
        this.data = data;
    }

    public BaseResponse(Integer errCode, String errMsg, Map<String, Object> info) {
        this.errCode = errCode;
        this.errMsg = errMsg;
        this.infos = info;
    }

    public BaseResponse(Long pageCount, Long count, Integer errCode, String errMsg, List<T> data) {
        super(pageCount, count);
        this.errCode = errCode;
        this.errMsg = errMsg;
        this.data = data;
    }

    public BaseResponse(Long currentIndex, Integer countPerPage, Long count, Integer errCode, String errMsg, List<T> data) {
        super(currentIndex, countPerPage, count);
        this.errCode = errCode;
        this.errMsg = errMsg;
        this.data = data;
    }
}
